﻿@model ITS.Core.ViewModel.Users.CreateUserViewModel
@{
    ViewBag.Title = "CreateRole";
}
@using (Html.BeginForm())
{
    @Html.ValidationSummary(false)
    @Html.HiddenFor(m => m.UserID)
    <div id="contentWrapper" class="create_role">
        <div class="editor-label">
            Username:
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.Username, new { @class = "Textbox", autocomplete = "off" })
            <span id="checkUsernameResult"></span>
        </div>
        <div class="editor-label">
            Password:
        </div>
        <div class="editor-field">
            @Html.PasswordFor(m => m.Password, new { @class = "Textbox", autocomplete = "off" })
            <span>Assign password for user.</span>
        </div>
        <div class="editor-label">
            Confirm Password:
        </div>
        <div class="editor-field">
            @Html.PasswordFor(m => m.Password2, new { @class = "Textbox", autocomplete = "off" })
            <span>Re-enter the password.</span>
        </div>
        <br />
        <fieldset>
            <legend>User's roles</legend>
            @for (int i = 0; i < Model.SelectRoleModels.Count; i++)
            {
                @Html.HiddenFor(m => m.SelectRoleModels[i].RoleID)
                @Html.HiddenFor(m => m.SelectRoleModels[i].RoleName)
                <div class="editor-label">
                    <span>
                        @Html.CheckBoxFor(model => model.SelectRoleModels[i].Checked, new { @class = "Checkbox" })
                    </span><span>
                        @Model.SelectRoleModels[i].RoleName</span>
                    @Html.HiddenFor(model => model.SelectRoleModels[i].Description)
                </div>
            }
        </fieldset>
        <br />
        <fieldset>
            <legend>User's information</legend>
            <table>
                <tr>
                    <td>
                        <div class="editor-label">
                            Display Name:
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            @Html.TextBoxFor(m => m.DisplayName, new { @class = "Textbox", autocomplete = "off" })
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="editor-label">
                            Email:
                        </div>
                    </td>
                    <td>
                        @Html.TextBoxFor(m => m.Email, new { @class = "Textbox", autocomplete = "off" })
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="editor-label">
                            Website:
                        </div>
                    </td>
                    <td>
                        @Html.TextBoxFor(m => m.Website, new { @class = "Textbox", autocomplete = "off" })
                    </td>
                </tr>
            </table>
        </fieldset>
        <div class="editor-label">
            Comment:
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.Description, new { @class = "Textbox" })
            <span>Comment for this user.</span>
        </div>
        <p>
            <input type="submit" causesvalidation="true" value="Create" id="submit_toogle" />
        </p>
        <p>
            @Html.ActionLink("Cancel", "Index", "Home")
        </p>
    </div>
}
<script type="text/javascript">
    $('#Username').blur(function () {
        var usr = document.getElementById("Username").value;
        $.post('@Url.Action("IsExisting","User")', { 'username': usr },
            function (result) {
                if (result.returnvalue) {
                    document.getElementById("checkUsernameResult").innerHTML = "This username is not available";
                }
                else {
                    document.getElementById("checkUsernameResult").innerHTML = "OK. This username is available";
                }
            });
    });
</script>
